﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Collections;
using Webchatting.Common;
using Webchatting.Dal;

public partial class server_SearchFriends : System.Web.UI.Page
{
    public static ArrayList arrRUIds = new ArrayList();
    public static ArrayList arrRUNickNames = new ArrayList();
    public static ArrayList arrRUPortraits = new ArrayList();
    public static ArrayList arrRUDess = new ArrayList();
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btnSerachFriend_Click(object sender, EventArgs e)
    {
        OperationFriends OF = new OperationFriends();

        string serachFriends = OF.SerachFriend(txtSearchFriends.Text.Trim(), arrRUIds, arrRUNickNames, arrRUPortraits,arrRUDess);

        ltlResult.Text = "<b>搜索结果：</b><br/>" + serachFriends;
        ltlText.Text = "<b>请选择要添加好友的ID：</b>";

        ddlAddFriend.Visible = true;
        btnAddFriend.Visible = true;

        while (ddlAddFriend.Items.Count > 0)
        {
            ddlAddFriend.Items.RemoveAt(0);
        }

        for (int i = 0; i < arrRUIds.Count; i++)
        {
            ddlAddFriend.Items.Add(new ListItem((string)arrRUIds[i], (string)arrRUIds[i]));
        }
    }
    protected void btnAddFriend_Click(object sender, EventArgs e)
    {
        OperationFriends OFriend = new OperationFriends();

        int selected = ddlAddFriend.SelectedIndex;
        FormsIdentity id = (FormsIdentity)User.Identity;
       
        try
        {
           
        
            OFriend.AddFriend(id.Ticket.UserData.Split('@')[0], ddlAddFriend.SelectedValue, 
                arrRUNickNames[selected].ToString(), id.Ticket.UserData.Split("@".ToCharArray())[1],
                arrRUPortraits[selected].ToString(), id.Ticket.UserData.Split("@".ToCharArray())[2], 
                arrRUDess[selected].ToString(), id.Ticket.UserData.Split("@".ToCharArray())[3]);

            Response.Write("<script>alert('添加好友成功!');window.parent.location.href='SearchFriends.aspx';</script>");
       }
        catch
        {
            Javascript.GoHistory(-1, "已经存在此好友，请不要重复添加！", Page);
        }
    }
}